package cn.bcsp.hotevent.service.impl;

import cn.bcsp.hotevent.pojo.Hotevents;
import cn.bcsp.hotevent.mapper.HoteventsMapper;
import cn.bcsp.hotevent.service.IHoteventsService;
import cn.bcsp.hotevent.util.PageUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-08-21
 */
@Service
public class HoteventsServiceImpl extends ServiceImpl<HoteventsMapper, Hotevents> implements IHoteventsService {

    @Resource
    private HoteventsMapper hoteventsMapper;

    @Override
    public PageUtil<Hotevents> querySysUserByPage(String keyWord, int currentPage) {

        PageUtil<Hotevents> pageUtil = new PageUtil<>();
        //总记录数
        int totalCount = hoteventsMapper.selectCount(keyWord);
        //每页显示的条数
        int pageSize = 5;
        pageUtil.setTotalCount(totalCount);
        pageUtil.setPageSize(pageSize);
        //当前页
        pageUtil.setCurrentPage(currentPage);
        //获得每页开始条数
        int startRow = pageUtil.getStartRow();
        //当前页的数据
        List<Hotevents> list = hoteventsMapper.selectWhere(keyWord, startRow, pageSize);
        //在pageUtil中封装当前页的数据
        pageUtil.setLists(list);

        return pageUtil;
    }

    @Override
    public Hotevents queryById(Integer id) {
        return hoteventsMapper.selectById(id);
    }

    @Override
    public int editInto(Integer id) {
        return hoteventsMapper.update(id);
    }
}
